import requests
import pytest


class TestRequest():

    @pytest.mark.parametrize("username, password, expected_status_code, expected_text", [
        ("wangwu", "123", 200, "success"),
        ("wangwu1", "123", 200, "登录失败，用户名或者密码错误"),
        ("wangwu", "1234", 200, "登录失败，用户名或者密码错误"),
        ("", "123", 200, "用户名不能为空"),
        ("wangwu", "", 200, "密码不能为空")
    ])
    def test_request_data_post(self, username, password, expected_status_code, expected_text):
        # 将入参定义为字典
        user = {"username": username, "password": password}

        # 发送POST请求
        resp = requests.post("http://127.0.0.1:8080/shop/mlogin", data=user)

        # 打印响应信息
        print(f"Status Code: {resp.status_code}")
        print(f"Response Text: {resp.text}")

        # 断言验证
        assert expected_status_code == resp.status_code
        assert expected_text in resp.text